using System.Text.Json.Serialization;
 
namespace SageKing.Studio.Models;

/// <summary>
/// Represents a dynamic expression.
/// </summary>
public class ExpressionJson
{
    /// <summary>
    /// Initializes a new instance of the <see cref="ExpressionJson"/> class.
    /// </summary>
    [JsonConstructor]
    public ExpressionJson()
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="ExpressionJson"/> class.
    /// </summary>
    /// <param name="type">The type of the expression.</param>
    /// <param name="value">The expression.</param>
    public ExpressionJson(string type, string? value = default)
    {
        Type = type;
        Value = value;
    }
    
    /// <summary>
    /// Gets or sets the expression type.
    /// </summary>
    public string Type { get; set; } = default!;

    /// <summary>
    /// Gets or sets the value representing the expression.
    /// </summary>
    public object? Value { get; set; }

    /// <summary>
    /// Returns the C# expression.
    /// </summary>
    public override string ToString() => Value?.ToString() ?? "";
    
    /// <summary>
    /// Creates a literal expression.
    /// </summary>
    public static ExpressionJson CreateLiteral(string value) => new("Literal", value);
    
    /// <summary>
    /// Creates an object expression.
    /// </summary>
    public static ExpressionJson CreateObject(string value) => new("Object", value);
}